//
//  MBDModifyUserWeChatViewModel.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/25.
//

import Foundation
import Alamofire
import SwiftyJSON

class MBDModifyUserWeChatViewModel : NSObject {
    var cellModels : Array<Any>!

    open var placeHolder : String
    open var title : String
    
    init(placeHolder: String = "", title: String = "") {
        
        self.placeHolder = placeHolder
        self.title = title
        
        var cellModels = [Any]()

        let cellModel0 = MBDModifyInfoTextFieldEditCellModel()
        cellModel0.textLimit = 30
        cellModel0.text = placeHolder
        cellModels.append(cellModel0)
                
        self.cellModels = cellModels
    }
    
    
    func doRequest(info: String, type : MBDModyfiyInfoType = .nickName,completion : @escaping ( _ error : NSError?,_ result : Bool)->()) {
        
        if let current = MBDAccountInfoModel.current() {
            var params : Dictionary<String, Any> = ["userId":String(current.userId),"weChatNumber": info]
            
            MBDHttpClient.shared.request("/user/update",method: .put,parameters: params,encoding: JSONEncoding.default).httpClientResponse { error, response in
                if nil != error {
                    completion(error!,false)
                } else {
                    let rawDict = response?.rawDict!
                    completion(nil,true)
                }
            }
        }
    }
}
